<?php


class AppHelper extends Helper {

/******************************************************************************/

var $autoLanguage = NULL;
var $autoPage = NULL;
var $autoPrefixes = NULL;
var $autoParams = NULL;
var $autoNamed = NULL;
var $autoExtensions = NULL;

/******************************************************************************/

function url($url = NULL, $full = FALSE) {
	if (is_null($url) || is_array($url)) {
		// autoLanguage
		$autoLanguage = (bool)Configure::read('Routing.autoLanguage');
		if (isset($url['autoLanguage'])) {
			$autoLanguage = (bool)$url['autoLanguage'];
			unset($url['autoLanguage']);
		} elseif (!is_null($this->autoLanguage)) {
			$autoLanguage = (bool)$this->autoLanguage;
		}
		if ($autoLanguage && !isset($url['language']) && isset($this->params['language'])) {
			$url['language'] = $this->params['language'];
		}
		if ($autoLanguage && !isset($url['lang']) && isset($this->params['lang'])) {
			$url['lang'] = $this->params['lang'];
		}
		// autoPage
		$autoPage = (bool)Configure::read('Routing.autoPage');
		if (isset($url['autoPage'])) {
			$autoPage = (bool)$url['autoPage'];
			unset($url['autoPage']);
		} elseif (!is_null($this->autoPage)) {
			$autoPage = (bool)$this->autoPage;
		}
		if ($autoPage && !isset($url['page']) && isset($this->params['named']['page'])) {
			$url['page'] = $this->params['named']['page'];
		}
		// autoPrefixes
		$autoPrefixes = (array)Configure::read('Routing.autoPrefixes');
		if (isset($url['autoPrefixes'])) {
			$autoPrefixes = array_merge($autoPrefixes, (array)$url['autoPrefixes']);
			unset($url['autoPrefixes']);
		} elseif (!is_null($this->autoPrefixes)) {
			$autoPrefixes = array_merge($autoPrefixes, (array)$this->autoPrefixes);
		}
		foreach ($autoPrefixes as $prefix) {
			if (!isset($url[$prefix]) && isset($this->params[$prefix]) && (bool)$this->params[$prefix]) {
				$url[$prefix] = TRUE;
			}
		}
		// autoParams
		$autoParams = (array)Configure::read('Routing.autoParams');
		if (isset($url['autoParams'])) {
			$autoParams = array_merge($autoParams, (array)$url['autoParams']);
			unset($url['autoParams']);
		} elseif (!is_null($this->autoParams)) {
			$autoParams = array_merge($autoParams, (array)$this->autoParams);
		}
		foreach ($autoParams as $arg) {
			if (!isset($url[$arg]) && isset($this->params[$arg])) {
				$url[$arg] = $this->params[$arg];
			}
		}
		// autoNamed
		$autoNamed = (array)Configure::read('Routing.autoNamed');
		if (isset($url['autoNamed'])) {
			$autoNamed = array_merge($autoNamed, (array)$url['autoNamed']);
			unset($url['autoNamed']);
		} elseif (!is_null($this->autoNamed)) {
			$autoNamed = array_merge($autoNamed, (array)$this->autoNamed);
		}
		foreach ($autoNamed as $arg) {
			if (!isset($url[$arg]) && isset($this->params['named'][$arg])) {
				$url[$arg] = $this->params['named'][$arg];
			}
		}
		// autoExtensions
		$autoExtensions = (array)Configure::read('Routing.autoExtensions');
		if (isset($url['autoExtensions'])) {
			$autoExtensions = array_merge($autoExtensions, (array)$url['autoExtensions']);
			unset($url['autoExtensions']);
		} elseif (!is_null($this->autoExtensions)) {
			$autoExtensions = array_merge($autoExtensions, (array)$this->autoExtensions);
		}
		foreach ($autoExtensions as $ext) {
			if (!isset($url['ext']) && isset($this->params['url']['ext']) && ($ext === $this->params['url']['ext'])) {
				$url['ext'] = $this->params['url']['ext'];
			}
		}
	}
	return parent::url($url, $full);
}

/******************************************************************************/

function urlIndex($rubric_id = NULL, $full = FALSE) {
	return $this->url(array('action' => 'index', $rubric_id), $full);
}

function urlView($id = NULL, $full = FALSE) {
	return $this->url(array('action' => 'view', 'id' => $id), $full);
}

/******************************************************************************/

function urlIndexPage($rubric_id = NULL, $full = FALSE) {
	return $this->url(array('action' => 'index', $rubric_id, 'autoPage' => TRUE), $full);
}

function urlViewPage($id = NULL, $full = FALSE) {
	return $this->url(array('action' => 'view', 'id' => $id, 'autoPage' => TRUE), $full);
}

/******************************************************************************/

}


?>